<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false"
  CodeFile="LoginInformation.aspx.vb" Inherits="LoginInformation" Title="AVS Login Information" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
  <asp:SqlDataSource ID="sqlVendors" runat="server" ConnectionString="<%$ ConnectionStrings:VendorStatsConnectionString %>"
    SelectCommand="SELECT [VendorId], [Name] FROM [Vendors] ORDER BY [Name]"></asp:SqlDataSource>
  <asp:SqlDataSource ID="sqlVendorOptions" runat="server" 
  ConnectionString="<%$ ConnectionStrings:VendorStatsConnectionString %>" 
  SelectCommand="SELECT [Option1], [Option2] FROM [Vendors] WHERE ([VendorId] = @VendorId)">
    <SelectParameters>
      <asp:ControlParameter ControlID="ddlVendors" Name="VendorId" 
        PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>
  <asp:SqlDataSource ID="sqlColleges" runat="server" ConnectionString="<%$ ConnectionStrings:VendorStatsConnectionString %>"
    SelectCommand="SELECT [CollegeId], [ShortName] FROM [Colleges] ORDER BY [ShortName]">
  </asp:SqlDataSource>
  <asp:SqlDataSource ID="sqlLoginInformation" runat="server" ConnectionString="<%$ ConnectionStrings:VendorStatsConnectionString %>"
    SelectCommand="SELECT LoginInformationId, VendorId, ShortName, CollegeId, UserName, Password, Option1, Option2, StartDate, EndDate FROM View_LoginInformation WHERE (VendorId = @VendorId) ORDER BY ShortName"
    DeleteCommand="DELETE FROM [LoginInformation] WHERE [LoginInformationId] = @LoginInformationId"
    InsertCommand="INSERT INTO LoginInformation(CollegeId, VendorId, UserName, Password, Option1, Option2, StartDate, EndDate) VALUES (@CollegeId, @VendorId, @UserName, @Password, @Option1, @Option2, @StartDate, @EndDate)"
    UpdateCommand="UPDATE LoginInformation SET UserName = @UserName, Password = @Password, Option1 = @Option1, Option2 = @Option2, StartDate = @StartDate, EndDate = @EndDate WHERE (LoginInformationId = @LoginInformationId)">
    <SelectParameters>
      <asp:ControlParameter ControlID="ddlVendors" Name="VendorId" PropertyName="SelectedValue"
        Type="Int32" />
    </SelectParameters>
    <DeleteParameters>
      <asp:Parameter Name="LoginInformationId" Type="Int32" />
    </DeleteParameters>
    <UpdateParameters>
      <asp:Parameter Name="UserName" Type="String" />
      <asp:Parameter Name="Password" Type="String" />
      <asp:Parameter Name="Option1" Type="String" />
      <asp:Parameter Name="Option2" Type="String" />
      <asp:Parameter Name="StartDate" Type="DateTime"/>
      <asp:Parameter Name="EndDate" type="DateTime"/>
      <asp:Parameter Name="LoginInformationId" Type="Int32" />
    </UpdateParameters>
    <InsertParameters>
      <asp:Parameter Name="CollegeId" Type="Int32" />
      <asp:Parameter Name="VendorId" Type="Int32" />
      <asp:Parameter Name="UserName" Type="String" />
      <asp:Parameter Name="Password" Type="String" />
      <asp:Parameter Name="Option1" Type="String" />
      <asp:Parameter Name="Option2" Type="String" />
      <asp:Parameter Name="StartDate" type="datetime"/>
      <asp:Parameter Name="EndDate" type="DateTime" />
    </InsertParameters>
  </asp:SqlDataSource>
  <br />
  <asp:FormView ID="FormView1" runat="server" DataSourceID="sqlLoginInformation" DataKeyNames="LoginInformationId">
    <InsertItemTemplate>
      Vendor:<asp:DropDownList ID="ddlVendors" runat="server" DataSourceID="sqlVendors"
        DataTextField="Name" DataValueField="VendorId" Width="170px" AutoPostBack="True"
        SelectedValue='<%# Bind("VendorId") %>'>
      </asp:DropDownList>
      <br />
      College:
      <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sqlColleges" DataTextField="ShortName"
        DataValueField="CollegeId" Width="170px" AutoPostBack="True" SelectedValue='<%# Bind("CollegeId") %>'>
      </asp:DropDownList><br />
      UserName:
      <asp:TextBox ID="UserNameTextBox" runat="server" Text='<%# Bind("UserName") %>'></asp:TextBox><br />
      Password:
      <asp:TextBox ID="PasswordTextBox" runat="server" Text='<%# Bind("Password") %>'></asp:TextBox><br />
      Option1:
      <asp:TextBox ID="Option1TextBox" runat="server" Text='<%# Bind("Option1") %>'></asp:TextBox><br />
      Option2:
      <asp:TextBox ID="Option2TextBox" runat="server" Text='<%# Bind("Option2") %>'></asp:TextBox><br />
      Start Date:
      <asp:TextBox ID="StartDateTextBox" runat="server" 
        Text='<%# Bind("StartDate") %>' CausesValidation="True"></asp:TextBox>
      <asp:RangeValidator ID="RangeValidator2" runat="server" 
        ControlToValidate="StartDateTextBox" 
        ErrorMessage="Instead of blank, use 1/1/1900" ForeColor="Maroon" 
        MaximumValue="01/01/2050" MinimumValue="01/01/1900" 
        Type="Date"></asp:RangeValidator>
      <br />
      End Date:
      <asp:TextBox ID="EndDateTextBox" runat="server" Text='<%# Bind("EndDate") %>'></asp:TextBox>
      <asp:RangeValidator ID="RangeValidator1" runat="server" 
        ControlToValidate="EndDateTextBox" 
        ErrorMessage="Instead of blank, use 1/1/2050 " ForeColor="Maroon" 
        MaximumValue="01/01/2050" MinimumValue="01/01/1900" 
        Type="Date"></asp:RangeValidator>
      <br />
      <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
        Text="Insert"></asp:LinkButton>
      <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
        Text="Cancel"></asp:LinkButton>
    </InsertItemTemplate>
    <ItemTemplate>
      <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
        Text="Add Login Information"></asp:LinkButton>
    </ItemTemplate>
    <EmptyDataTemplate>
      <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
        Text="Add New Login Information"></asp:LinkButton>
    </EmptyDataTemplate>
  </asp:FormView>
  <br />
  <asp:DropDownList ID="ddlVendors" runat="server" DataSourceID="sqlVendors" DataTextField="Name"
    DataValueField="VendorId" Width="170px" AutoPostBack="True">
  </asp:DropDownList>
<br />
<asp:DataList ID="DataList1" runat="server" DataSourceID="sqlVendorOptions" 
  RepeatLayout="Flow">
  <ItemTemplate>
    Option1:
    <asp:Label ID="Option1Label" runat="server" Text='<%# Eval("Option1") %>' />
    <br />
    Option2:
    <asp:Label ID="Option2Label" runat="server" Text='<%# Eval("Option2") %>' />
    <br />
    <br />
  </ItemTemplate>
</asp:DataList>
  <br />
  <asp:GridView ID="gvLoginInformation" runat="server" AutoGenerateColumns="False"
    DataKeyNames="LoginInformationId" DataSourceID="sqlLoginInformation">
    <Columns>
      <asp:TemplateField>
        <ItemTemplate>
          <asp:LinkButton runat="server" CommandName="Edit">Edit</asp:LinkButton>
          <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="return confirm('WARNING: Do you really want to set the start date and end date instead?');"
            CommandName="Delete">Delete</asp:LinkButton>
        </ItemTemplate>
        <EditItemTemplate>
          <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Update">Update</asp:LinkButton>
          <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Cancel">Cancel</asp:LinkButton>
        </EditItemTemplate>
      </asp:TemplateField>
      <asp:BoundField DataField="LoginInformationId" HeaderText="LoginInformationId" ReadOnly="True"
        SortExpression="LoginInformationId" Visible="False" />
      <asp:BoundField DataField="ShortName" HeaderText="ShortName" ReadOnly="True" SortExpression="ShortName" />
      <asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
      <asp:BoundField DataField="Password" HeaderText="Password" SortExpression="Password" />
      <asp:BoundField DataField="Option1" HeaderText="Option1" SortExpression="Option1" />
      <asp:BoundField DataField="Option2" HeaderText="Option2" SortExpression="Option2" />
      <asp:BoundField DataField="StartDate" HeaderText="Start Date" SortExpression="StartDate" DataFormatString="{0:d}" HtmlEncode="False" />
      <asp:BoundField DataField="EndDate" HeaderText="End Date" SortExpression="EndDate" DataFormatString="{0:d}" HtmlEncode="False" />
    </Columns>
  </asp:GridView>
</asp:Content>
